package org.lex.collection.tree.diff;

public class Diff<T> {
	public T oldObject;
	public T newObject;
	public boolean visited = false;

	public static <T> Diff<T> valueOf(T o, T n) {
		Diff<T> p = new Diff<T>();
		p.oldObject = o;
		p.newObject = n;
		return p;
	}

	public String toString() {
		return "[old=" + oldObject + ", new=" + newObject + "]\n";
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((newObject == null) ? 0 : newObject.hashCode());
		result = prime * result + ((oldObject == null) ? 0 : oldObject.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Diff<?> other = (Diff<?>) obj;
		if (newObject == null) {
			if (other.newObject != null)
				return false;
		} else if (!newObject.equals(other.newObject))
			return false;
		if (oldObject == null) {
			if (other.oldObject != null)
				return false;
		} else if (!oldObject.equals(other.oldObject))
			return false;
		return true;
	}
}